<?php
/***************************************************************************
 *   Professional Download System                                          *
 *                                                                         *
 *   Copyright (C) pirdani                                                 *
 *   pirdani@hotmail.de                                                    *
 *   http://pirdani.de/                                                    *
 *                                                                         *
 *   Copyright (C) 2005 EdEdster (Stefan Noss)                             *
 *   http://edsterathome.de/                                               *
 *                                                                         *
 *   Copyright (C) 2006-2008 Artur Wiebe                                   *
 *   wibix@gmx.de                                                          *
 *   http://wibix.de/                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/maincore.php';
require_once(INFUSIONS.'pro_download_panel/include/core.php');

if(!iPDP_CAN_VIEW
	&& !in_array(FUSION_SELF, array('error.php', 'copyright.php'))) {
	fallback(INFUSIONS.'pro_download_panel/error.php?type=access');
}

switch(FUSION_VERSION) {
case 6:
	require_once(BASEDIR.'subheader.php');
	require_once(BASEDIR.'side_left.php');
	break;
case 7:
	require_once(THEMES.'templates/header.php');
	break;
case 'FF':
	break;
default:
	die;
}



/*
 * get download
 */
require_once(INFUSIONS.'pro_download_panel/include/class.download.php');
$download = new pdpDownload(isset($_GET['did']) && isNum($_GET['did'])
	? $_GET['did']
	: 0);


if($download->id && $download->status!=PDP_PRO_ON && !$download->can_edit) {
	fallback('download.php?catid='.$download->data['cat_id']);
}


/*
 * FUNCS
 */
// bb-buttons and smileys
function pdp_get_bb_smileys($input, $val, $is_enabled, $show_smileys=true) {
	global $locale;
	if(FUSION_VERSION==7) {
		include_once(INCLUDES.'bbcode_include.php');
		return display_bbcodes('98%', $input)
.($is_enabled
	? '<div><label><input type="checkbox" name="disable_smileys" value="'.$val.'"'
		.($val=='0'
			? ' checked="checked"'
			: ''
		).' /> '.$locale['PDP041'].'</label></div>'
: '');
	} else {
		return '
<input type="button" value="b" class="button" style="font-weight:bold;"
	onclick="addText(\''.$input.'\', \'[b]\', \'[/b]\');" />
<input type="button" value="i" class="button" style="font-style:italic;"
	onclick="addText(\''.$input.'\', \'[i]\', \'[/i]\');" />
<input type="button" value="u" class="button" style="text-decoration:underline;"
	onclick="addText(\''.$input.'\', \'[u]\', \'[/u]\');" />
<input type="button" value="url" class="button"
	onclick="addText(\''.$input.'\', \'[url]\', \'[/url]\');" />
<input type="button" value="mail" class="button"
	onclick="addText(\''.$input.'\', \'[mail]\', \'[/mail]\');" />
<input type="button" value="img" class="button"
	onclick="addText(\''.$input.'\', \'[img]\', \'[/img]\');" />
<input type="button" value="center" class="button"
	onclick="addText(\''.$input.'\', \'[center]\', \'[/center]\');" />
<input type="button" value="small" class="button"
	onclick="addText(\''.$input.'\', \'[small]\', \'[/small]\');" />
<input type="button" value="code" class="button"
	onclick="addText(\''.$input.'\', \'[code]\', \'[/code]\');" />
<input type="button" value="quote" class="button"
	onclick="addText(\''.$input.'\', \'[quote]\', \'[/quote]\');" />'
.($show_smileys
	? '<div>'.displaysmileys($input).'</div>'
	: '')
.($is_enabled
	? '<div><label><input type="checkbox" name="disable_smileys" value="'.$val.'"'
		.($val=='0'
			? ' checked="checked"'
			: ''
		).' /> '.$locale['PDP041'].'</label></div>'
: '');
	}
}


function pdp_cleanup_filename($filename)
{
	$filename = preg_replace('/__\d+\.\S$/', '', $filename);
	$filename = preg_replace('/\[\d+\]\.\S$/', '', $filename);
	return $filename;
}


function pdp_is_external($url)
{
	return (substr($url, 0, 7)=='http://'
		|| substr($url, 0, 8)=='https://'
		|| substr($url, 0, 6)=='ftp://');
}





function pdp_tabs($tabs)
{
	if(!defined('IN_FF')) {
		return;
	}

	if(!defined('FF_TABS')) {
		define('FF_TABS',	true);
	}
?>
<script type="text/javascript">
FF.behaviors.pdp_tabs = function(content){
	$("#pdp_tabs > ul").tabs();
};
</script>
<?php

	echo '
<!--TABS.open-->
<div id="pdp_tabs">
	<ul>';
	foreach($tabs as $tab_id => $tab_title) {
		echo '
		<li><a href="#'.$tab_id.'"><span>'.$tab_title.'</span></a></li>';
	}
	echo '
	</ul>';
}

function pdp_tabs_close()
{
	if(!defined('IN_FF')) {
		return;
	}

	echo '
</div>
<!--TABS.close-->';
}


function pdp_open_tab($name, $caption)
{
	if(defined('IN_FF')) {
		echo '<div id="'.$name.'">';
	} else {
		opentable($caption);
	}
}
function pdp_close_tab()
{
	if(defined('IN_FF')) {
		echo '</div>';
	} else {
		closetable();
	}
}


function pdp_icon($name, $desc)
{
	if(substr($name, -4)!='.gif') {
		$name .= '.png';
	}
	return '<img src="'.INFUSIONS.'pro_download_panel/icons/'.$name.'" alt="'.$desc.'" title="'.$desc.'" border="0">';
}

function pdp_add_to_title($text)
{
	switch(FUSION_VERSION) {
	case 'FF':
		ff_add_to_title($text);
		break;
	case 7:
		add_to_title($text);
		break;
	}
}

?>
